home *** CD-ROM | disk | FTP | other *** search
- on startMovie
- global gReadyToGo, gMovieStartTime
- set gReadyToGo to 0
- set gMovieStartTime to the ticks
- initPreloadStuff()
- netAbort()
- localInit()
- pass()
- end
-
- on initPreloadStuff
- global gBaseURL, gMaxWaitTime, gMaxRetries, gPreloadList, gLoadStatus, gCurrLoading, gPreloadingOn, gRetries
- set gMaxWaitTime to 22 * 60
- set gMaxRetries to 3
- if not gRetries then
- set gRetries to 0
- end if
- if not gPreloadList then
- set gPreloadList to []
- end if
- if not gLoadStatus then
- set gLoadStatus to []
- end if
- if not gCurrLoading then
- set gCurrLoading to EMPTY
- end if
- set gPreloadingOn to 0
- end
-
- on addToLoadQueue theFile
- global gPreloadList, gLoadStatus
- if gLoadStatus <> "[]" then
- repeat with i = 1 to count(gLoadStatus)
- if getPos(getAt(gLoadStatus, i), theFile) = 1 then
- exit
- end if
- end repeat
- end if
- set PropTemplate to [#name: theFile, #ID: 0, #loaded: 0, #error: EMPTY]
- append(gPreloadList, theFile)
- append(gLoadStatus, PropTemplate)
- end
-
- on checkQueue
- global gCurrLoading, gLoadStatus, gBaseURL, gRetries, gMaxRetries
- if gLoadStatus <> [] then
- if gCurrLoading = EMPTY then
- set gCurrLoading to 0
- end if
- if not (gCurrLoading > count(gLoadStatus)) and (gCurrLoading <> 0) then
- set currLoaded to getaProp(getAt(gLoadStatus, gCurrLoading), #loaded)
- if (currLoaded = 1) and (count(gLoadStatus) > gCurrLoading) then
- set gCurrLoading to gCurrLoading + 1
- put "checkQueue:wake up"
- set currID to getLoadID(getaProp(getAt(gLoadStatus, gCurrLoading), #name))
- setaProp(getAt(gLoadStatus, gCurrLoading), #ID, currID)
- end if
- set currID to getaProp(getAt(gLoadStatus, gCurrLoading), #ID)
- if (netDone(currID) = 1) and (getaProp(getAt(gLoadStatus, gCurrLoading), #loaded) = 0) then
- if netError(currID) = "OK" then
- if not (NetTextResult(gCurrID) contains "not found") then
- put "checkQueue:recv OK, updating"
- setaProp(getAt(gLoadStatus, gCurrLoading), #loaded, 1)
- else
- setaProp(getAt(gLoadStatus, gCurrLoading), #loaded, 0)
- setaProp(getAt(gLoadStatus, gCurrLoading), #error, "not found")
- end if
- if count(gLoadStatus) > gCurrLoading then
- put "checkQueue:get new"
- set gCurrLoading to gCurrLoading + 1
- set currID to getLoadID(getaProp(getAt(gLoadStatus, gCurrLoading), #name))
- setaProp(getAt(gLoadStatus, gCurrLoading), #ID, currID)
- set gRetries to 0
- end if
- else
- if netError(currID) = EMPTY then
- nothing()
- else
- if netError(currID) contains "error" then
- put "checkQueue:transfer error"
- if gRetries > gMaxRetries then
- if count(gLoadStatus) > gCurrLoading then
- set gCurrLoading to gCurrLoading + 1
- else
- set gRetries to gRetries + 1
- exit
- end if
- end if
- set currID to getLoadID(getaProp(getAt(gLoadStatus, gCurrLoading), #name))
- setaProp(getAt(gLoadStatus, gCurrLoading), #ID, currID)
- end if
- end if
- end if
- end if
- else
- set gCurrLoading to gCurrLoading + 1
- put "checkQueue:starting up"
- set currID to getLoadID(getaProp(getAt(gLoadStatus, gCurrLoading), #name))
- setaProp(getAt(gLoadStatus, gCurrLoading), #ID, currID)
- end if
- else
- if gCurrLoading <> EMPTY then
- set gCurrLoading to EMPTY
- end if
- end if
- end
-
- on getLoadID theFile
- PreloadNetThing(theFile)
- set currID to GetLatestNetID()
- return currID
- end
-
- on clearPreloadList
- global gLoadStatus, gCurrLoading
- set gLoadStatus to []
- set gCurrLoading to EMPTY
- end
-
- on preloadRange start, stop
- preLoadCast(start, stop)
- put "loaded to " & the result
- end
-
- on WaitForTicks theTicks
- set startTime to the timer
- repeat while (startTime + theTicks) > the timer
- nothing()
- end repeat
- end
-
- on goMovie theMovie
- global gPreloadingOn, gCurrLoading, gLoadStatus, gBaseURL, gReadyToGo
- if not (theMovie contains ".dcr") then
- set theMovie to theMovie & ".dcr"
- end if
- if not (theMovie contains getaProp(getAt(gLoadStatus, gCurrLoading), #name)) then
- netAbort()
- end if
- set gPreloadingOn to 0
- set fadeDuration to 200
- if soundBusy(1) or soundBusy(2) then
- set lPlaying to 1
- end if
- if soundBusy(1) then
- sound fadeOut 1, fadeDuration
- end if
- if soundBusy(2) then
- sound fadeOut 2, fadeDuration
- end if
- if lPlaying = 1 then
- WaitForTicks(fadeDuration)
- end if
- set gReadyToGo to 1
- goToNetMovie(theMovie)
- end
-
- on goPage thePage
- global gPreloadingOn, gCurrLoading, gLoadStatus, gReadyToGo, gBaseURL
- if not (thePage contains getaProp(getAt(gLoadStatus, gCurrLoading), #name)) and not netDone() then
- netAbort()
- end if
- set gPreloadingOn to 0
- set gReadyToGo to 1
- GoToNetPage(thePage)
- set fadeDuration to 200
- if soundBusy(1) or soundBusy(2) then
- set lPlaying to 1
- end if
- if soundBusy(1) then
- sound fadeOut 1, fadeDuration
- end if
- if soundBusy(2) then
- sound fadeOut 2, fadeDuration
- end if
- if lPlaying = 1 then
- WaitForTicks(fadeDuration)
- end if
- end
-
- on idle
- global gPreloadingOn
- if gPreloadingOn = 1 then
- checkQueue()
- end if
- pass()
- end
-
- on getFileName theURL
- repeat with i = the number of chars in theURL down to 1
- if (char i of theURL = "/") or (char i of theURL = ":") then
- set rVal to char i + 1 to the number of chars in theURL of theURL
- exit repeat
- end if
- end repeat
- return rVal
- end
-